/**
 * Copyright (C), 2015, 上海赛可电子商务有限公司
 * Author:   张卫明
 * Date:     2016-6-23
 * Description: 详情页
 */

window.carColorList =  {};
window.imageUrl = cacheImageUrl.replace("/120x80", "");

(function(){

	var jsHiddenDataElm = $('#js_hidden_data');

	//色值 相关
	var colorListFun = {
		config: {
			outerColorListBox:$('#js_car_color'),
			innerColorListBox:$('#js_interior_color'),
			hiddenData:jsHiddenDataElm,
			formInsideColor:$('#js_form_inside_color'),
			totalAvailable:$('#js_total_available'),
			totalUsed:$('#js_total_used'),
			outerInitList:{
				cur:'',
				list:[]
			},
			innerInitList:{
				cur:'',
				list:[]
			},
			outerType:false,
			innerType:false
		},
		tabObj : null,
		scrollColorId:null,
		init:function(){
			
			//初始化状态
			this.reset();

			if(carColorList.hasInColor){
				this.createOuterColor();
				this.createInnerColor();
			} else {
				this.createOuterColor();
				this.config.formInsideColor.hide();
			}

			this.addEvent();
			this.initEvent();
			this.update();
			
			this.tabObj = this.addImageSwitchEvent();

			this.tabObj = this.addImageSwitchEvent();

		},
		reset:function(){

			var config = this.config;

			config.outerInitList = {
					cur:'',
					list:[]
				};

			config.innerInitList = {
					cur:'',
					list:[]
				};

			config.outerType = false;
			config.innerType = false;
			

			if(carColorList.totalAvailableNum<=0){
				$(".js_submit_preorder").hide();
				$(".js_submit_sellout").show();
			}else{
				$(".js_submit_preorder").show();
				$(".js_submit_sellout").hide();
			}

		},
		createOuterColor:function(){

			var   config = this.config,
				outerColorHtml = this.initHtml('outer');

			config['outerColorListBox'].html(outerColorHtml);

		},
		createInnerColor:function(){
			var   config = this.config,
				innerColorHtml = this.initHtml('inner');

			config['innerColorListBox'].html(innerColorHtml);
		},
		initHtml:function(_type){
			var colorList = carColorList[_type+'ColorList'],
				config = this.config,
				colorMap = carColorList[_type+'Map'],
				colorListHtml = '<ul class="color-list clearfix">',
				attrAvailableNum = '';

			for(var i=0;i<colorList.length;i++){
				//满足两种情况 可加'.has-amount' 类, 1 种 有内饰，1种无内饰
				if((colorMap[colorList[i]['colorId']] && colorMap[colorList[i]['colorId']].length>0) || (colorList[i]['availableNum'] &&  colorList[i]['availableNum']>0)){

					if(colorList[i]['availableNum'] && colorList[i]['availableNum']>0){
						attrAvailableNum = 'availablenum="'+colorList[i]['availableNum']+'"';
					}

					colorListHtml =colorListHtml + '<li colorid="'+colorList[i]['colorId']+'" skucode="'+colorList[i]['skuCode']+'"  colorname="'+colorList[i]['colorName']+'" class="has-amount"'+attrAvailableNum+'>';
					config[_type+'InitList']['list'].push(colorList[i]['colorId']);
				} else {
					colorListHtml =colorListHtml + '<li colorid="'+colorList[i]['colorId']+'" skucode="'+colorList[i]['skuCode']+'"  colorname="'+colorList[i]['colorName']+'"'+attrAvailableNum+'>';
				}
				colorListHtml =colorListHtml + '<img src="'+imageUrl+colorList[i]['colorImgPath']+'" alt="'+colorList[i]['colorName']+'" width="20" height="20">';
				colorListHtml =colorListHtml + '</li>';
			};
			colorListHtml =colorListHtml + '</ul>';
			colorListHtml =colorListHtml + '<div class="cur-color js_cur_color" style="display:none;">已选择：<span id="js_cur_'+_type+'color"></span></div>';
			return colorListHtml;
		},
		addEvent:function(){

			var  outerColorListBox = this.config.outerColorListBox,
				innerColorListBox = this.config.innerColorListBox,
				self = this;

			outerColorListBox.off('click').on('click','.has-amount',function(){
				self.changeColor($(this),'outer');
			});

			innerColorListBox.off('click').on('click','.has-amount',function(){
				self.changeColor($(this),'inner');
			});


		},
		initEvent:function(){
			//this.config.outerColorListBox.find(".has-amount").eq(0).trigger('click');
			//this.getCarSlide(this.scrollColorId);
		},
		update:function(){
			this.config.totalAvailable.html(carColorList.totalAvailableNum);
			this.config.totalUsed.html(carColorList.totalUsedNum);
		},
		//取消选中值
		cancelCur:function(self,type,noType,colorLi){

			var config = this.config,
				_self = this;

			config[type+'InitList']['cur'] = '';
			colorLi.removeClass('has-amount').removeClass('cur');
			$('#js_cur_'+type+'color').html('');
			$('#js_cur_'+type+'color').parents('.js_cur_color').hide();
			
			config[type+'Type'] = false;
			
			config.totalAvailable.html(carColorList.totalAvailableNum);
			colorLi.each(function(index,ele){
				for(var i = 0;i<config[noType+'InitList']['list'].length;i++){
					if(config[noType+'InitList']['list'][i] == $(this).attr('colorid')){
						$(this).addClass('has-amount');
						if(config[noType+'InitList']['cur'] == $(this).attr('colorid')){
							$(this).addClass('cur');
						}
					}
				}
			});

		},
		changeColor:function(self,type){
			
			var config = this.config,
				_self = this,
				noType = (type =='outer' ? 'inner':'outer'),
				colorNodes = config[type+'ColorListBox'].find(".has-amount"),
				colorNoNodes = config[noType+'ColorListBox'].find(".has-amount"),
				colorLi = config[noType+'ColorListBox'].find('li'),
				colorTexNode = $('#js_cur_'+type+'color'),
				colorId = self.attr('colorid'),
				skuCode = self.attr('skucode'),
				firstCur = 0;
			
			//点击已选中颜色等于取消全部选择的颜色
			if(self.hasClass('cur')){
				colorNodes.removeClass('cur');
				config.hiddenData.attr(type+'id','');

				_self.cancelCur(self,type,noType,colorLi);

				return false;
			}
			
			config[type+'Type'] = true;

			colorNodes.removeClass('cur');
			self.addClass('cur');
			config[type+'InitList']['cur'] = colorId;

			colorTexNode.html(self.attr('colorname'));
			$('#js_cur_'+type+'color').parents('.js_cur_color').show();

			colorLi.removeClass('has-amount');
			
			
			config.hiddenData.attr('skuCode',skuCode);
			config.hiddenData.attr(type+'id',colorId);

			if(type != 'inner'){
				 //触发焦点图
				 _self.getCarSlide(colorId);
			}
			
			//重置库存
			if($.trim(self.attr('availablenum')) && config[type+'Type'] && config[noType+'Type']){
				config.totalAvailable.html(self.attr('availablenum'));
			} else {
				config.totalAvailable.html(carColorList.totalAvailableNum);
			}
			//无内饰色选择
			if(!carColorList.hasInColor){
				config.totalAvailable.html(self.attr('availablenum'));
				return false;
			}
			colorLi.attr("availablenum",'');
			
			colorLi.each(function(index,ele){
				for(var i = 0;i<carColorList[type+'Map'][colorId].length;i++){
					if(carColorList[type+'Map'][colorId][i]['colorId'] == $(this).attr('colorid')){
						$(this).addClass('has-amount');
						$(this).attr('skucode',carColorList[type+'Map'][colorId][i]['skuCode']);
						$(this).attr("availablenum",carColorList[type+'Map'][colorId][i]['availableNum']);
						/*if(firstCur == 0){
							$(this).addClass('cur');
							$('#js_cur_'+noType+'color').html($(this).attr('colorname'));

							 //给提交按钮赋色值
							config.hiddenData.attr(noType+'id',$(this).attr('colorid'));

							if(type == 'inner'){
									//触发焦点图
									_self.getCarSlide($(this).attr('colorid'));
							} else {
								//获取首次轮播的colorid
								_self.scrollColorId = $(this).attr('colorid');
							}

						}
						firstCur++*/
					}
				};
			});
		},
		getCarSlide:function(colorId){

			var that = this,
			carImageShow = $("#js_car_imageshow"),
			hiddenData = jsHiddenDataElm;

			//获取车身轮播图片
			$.ajax({
				url:"/product/getPosAndColorImg.htm",
				type:'post',
//				url:"/mscarmall/mall/js/test-data/getPosAndColorImg.html",
//				type:'get',
				dataType: 'html',
				data:{
					ColorId:colorId,
					velModelId:window.velModelId,
					spuId:spuId
				},
				success:function(response){
					if(response != ""){
						carImageShow.html(response);
						if(that.tabObj){
							clearTimeout(that.tabObj.intInterval);
							that.tabObj.intInterval = -1;
							that.tabObj = null;
						}
						that.tabObj = that.addImageSwitchEvent();
					}
				},
				error:function(errorMessage){

				}
			});
		},
		//图片切换
		addImageSwitchEvent: function(){
			var options= {
				navNode: '.js_car_tabs li',
				curNavCls:'cur',
				pannelNode: '.js_car_photos li',
				curPannelCls:'cur',
				preNode: '',
				nextNode: '',
				duration: 5000,
				event: 'mouseenter',
				navMaskNode: 'em',
				navMaskCssObject:{"opacity":0.5},
				curMaskNavCssObject:{"opacity":0.12}
			};
			return ECar.tab(options);
		}
	};





	//买车逻辑 主函数
	var detailPayCar = {
		config:{
			selectType:$('.js_subset_select').val(),
			getColorType: true
		},
		init:function(){

			//首次初始化城市 及 对应 车颜色值
			this.getColorDate(undefined,'init');
			//选择贷款逻辑
			this.chooseLoan();
			//立即购买逻辑
			this.formSubmitPayCar();
		},
		//立即购买提交事件
		formSubmitPayCar:function(){
			var self = this;
			var submitNode = $(".js_submit_preorder");
				submitNode.on("click", function(){
					
					function verifyChoose(){
						var innerId=jsHiddenDataElm.attr("innerid"),
							outerId=jsHiddenDataElm.attr("outerid"),
							flag = 0;
						var firstShare = jsHiddenDataElm.attr("firstShare");
						if(outerId==undefined||outerId==""){
							self.showCommonTips("请选择车身颜色");
							flag = 0;
						}else if((innerId==undefined||innerId=="")&&carColorList.hasInColor){
							self.showCommonTips("请选择内饰颜色");
							flag = 0;
						}else if(window.isCheckLoan&&(firstShare==undefined||firstShare=="")){
							self.showCommonTips("请选择贷款方案");
							flag = 0;
						}else{
							flag = 1;
						}
						return flag;
					}
					if(verifyChoose()==1){
						window.needProduceObj = $(this);
						window.backCallName = 'goPayCar';
						checkLogin(MALL.accountQuickBase,'B');
					}
				});
		},
		//通用提示
		showCommonTips: function(msg){
			ECar.easyDialog.open({
				autoClose : 2000,
				container : {
					header : null,
					content : '<div class="tips-common">'+msg+'</div>'
				}
			});
		},
		//已经下单的提示
		showHasOrderTips: function(){
			ECar.easyDialog.open({
				container : {
					header : '提示',
					content : '<div class="tips-hasorder">尊敬的客户，由于您已经定购了该款车辆，请完成支付或者取消定单后再次购买，给您带来的不便还请谅解。<a onclick="ECar.easyDialog.close()" class="button-blue" target="_blank" href="'+memberBase+'/member/entireCarOrder.htm">查看我的定单</a></div>'
				}
			});
		},
		//立即购买提交事件依赖
		goPreOrderDetail: function(){

			var channel = jsHiddenDataElm.attr("channelId");
			var self = this;
			if(channel == 6||channel == 7){
				var hearTitle = "中国船舶活动专属入口";
				if(channel == 6){
					hearTitle = "中铁活动专属入口";
				}
				ECar.easyDialog.open({
					container : {
						header : hearTitle,
						content : '<div style="text-align:center; padding:20px 50px;"><input type="text" id="fcode" style="width:250px; height:36px;" placeholder="请输入邀请码"/></div>',
						yesFn : function(){
							var fcode = $("#fcode").val();
							jsHiddenDataElm.attr("verifyCode",$.trim(fcode));
							goSubscribe(self);
						},
						noFn : function(){
							return;
						},
						yesText : '确定',
						noText : '取消'
					}
				});
				return;
			}else{
				goSubscribe(self);
			}

			function goSubscribe(self){
				var $this = $(window.needProduceObj);
				//var self = this;
				$.ajax({
					url: "/preOrder/goSubscribeForBare.htm",
					type: "POST",
					data:{
						//basicInfo
						spuId:spuId,
						channelId:jsHiddenDataElm.attr("channelId"),
						detailId:jsHiddenDataElm.attr("skucode"),
						stockId:jsHiddenDataElm.attr("stockId"),
						cityId:jsHiddenDataElm.attr("cityid"),
						financeId:jsHiddenDataElm.attr("financeId"),
						storeId:jsHiddenDataElm.attr("storeId"),
						marketTagIds:jsHiddenDataElm.attr("marketTagId"),
						//color
						colorId:jsHiddenDataElm.attr("outerid"),
						innerId:jsHiddenDataElm.attr("innerid"),
						//loan
						firstShare:jsHiddenDataElm.attr("firstShare"),
						firstAmount:jsHiddenDataElm.attr("firstAmount"),
						repayPeriod:jsHiddenDataElm.attr("repayPeriod"),
						loanAmount:jsHiddenDataElm.attr("loanAmount"),
						monthRepay:jsHiddenDataElm.attr("monthRepay"),
						interest:jsHiddenDataElm.attr("interest"),
						financeServiceName:jsHiddenDataElm.attr("financeServiceName"),
						//qualification check
						verifyCode:jsHiddenDataElm.attr("verifyCode")
					},
					dataType: "json",
					success: function(data){
						if(data.parameterReturn==3){
							//跳转预定页
							window.location.href = data.url;
						}else if(data.parameterReturn==4){
							//F码验证错误
							self.showCommonTips("邀请码输入有误");
						}else if(data.parameterReturn==5){
							//F码验证错误
							self.showCommonTips("该邀请码已被使用，换张试试");
						}else if(data.parameterReturn==0){
							if(data.subscribeResult&&data.subscribeResult.resultCode==2){
								//（重复报名）新增业务逻辑，若商品超过限定用户购买数目提示
								self.showCommonTips("本商品限购"+ data.subscribeResult.subscriptionId +"辆，请勿重复购买");
							}else if(data.subscribeResult&&data.subscribeResult.resultCode==3){
								//商品卖完
								self.showCommonTips("尊敬的客户，您选择的该颜色商品已经被抢空，我们会尽快补充库存，谢谢。");
								setTimeout(function(){window.location.reload();},2100);
							}else if(data.subscribeResult&&data.subscribeResult.resultCode==4){
								//未开始
								self.showCommonTips("尊敬的客户，暂时无法定购，请稍后重试，给您带来的不便还请谅解。");
							}else if(data.subscribeResult&&data.subscribeResult.resultCode==5){
								//已结束
								self.showCommonTips("尊敬的客户，该商品已下架，请您继续关注。");
								setTimeout(function(){window.location.reload();},2100);
							}else if(data.subscribeResult&&data.subscribeResult.resultCode==6){
								//失败
								self.showCommonTips("尊敬的客户，暂时无法定购，请稍后重试，给您带来的不便还请谅解。");
							}else if(data.subscribeResult&&data.subscribeResult.resultCode==8){
								self.showHasOrderTips();
							}else if(data.subscribeResult&&data.subscribeResult.resultCode==9){
								//此款商品仅限叭叭节中奖用户购买，请您关注其他商品
								self.showCommonTips("此款商品仅限叭叭节中奖用户购买，请您关注其他商品。");
								setTimeout(function(){window.location.reload();},2100);
							}
						}else if(data==1){
							//用户未登录或者未绑定手机号
							self.showCommonTips("尊敬的客户，暂时无法定购，请稍后重试，给您带来的不便还请谅解。");
						}else if(data==2){
							//参数错误，不符合标准
							self.showCommonTips("尊敬的客户，暂时无法定购，请稍后重试，给您带来的不便还请谅解。");
						}else{
							//服务异常
							self.showCommonTips("尊敬的客户，暂时无法定购，请稍后重试，给您带来的不便还请谅解。");
						}
					}
				});
			}
		},
		//初始化城市三级联动
		formRegionSelect:function(_cityId){

			var _self = this;
			
			if(carColorList.saleCityLink.length <= 0 ){
				return ;
			}

			$('.js_city_select').attr('data-val',window.provinceId);
			$('.js_subset_select').attr('data-val',_cityId);

			var seriesSelect  = ECar.seriesSelect($(".js_form_region"), {
				 data: carColorList.saleCityLink,
				changeTitle: true,
				selects: ["js_city_select", "js_subset_select"],
				nodata: null,
				changeCur: function(){

					//首次初始化时 已经加载过改城市数据
					if(_self.config.getColorType){
						_self.config.getColorType = false;
						return;
					}
					
					//if($('.js_subset_select').val() != _self.config.selectType && $.trim($('.js_subset_select').val())){
					if(seriesSelect.returnData){
						var cityId = $('.js_subset_select').val();
						jsHiddenDataElm.attr('cityId',cityId);
						_self.getColorDate(cityId);
					};
				}
			 });

		},
		//获取 城市 ，色值  初始化 色值列表
		getColorDate: function(_cityId,_type){
			var self = this;

			if(!_cityId){
				_cityId = window.cityId;
			}
			if(window.spuStatus =="5"||window.spuStatus =="6"){
				$.ajax({
					url:"/product/getStock.htm",
					type:'get',
					dataType: 'json',
					cache:false,
					data:{
						 spuId:spuId,
						 cityId:_cityId
					  },
					 success:function(response){
						window.carColorList = response;
						if(_type && _type == 'init'){
							self.formRegionSelect(_cityId);
						}
						colorListFun.init();
					},
					error:function(a,b){
						console.log("/product/getStock.htm请求404");
					}
				});
			}
		},
		//获取Cookie
		getCookie: function(key) {
			var result = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)"));
			return result != null ? decodeURIComponent(result[2]) : null;
		},

		//选择金融方案
		chooseLoan : function() {
			var data = window.g_config.financeJson;
			var myLoan;
			var firstPopup = true;
			var dom = $($("#choose-loan-div").html());
			//弹窗逻辑
			$(".stages-btn, .js-loan").on("click", function() {
				if (firstPopup) {
					dom.find('.loan-item').remove();
					for (var key in data) {
						dom.find(".down-payment").append("<div class='loan-item' key='" + key + "'>" + Math.ceil(key) + "%</div>");
					}
					ECar.easyDialog.open({
						container : {
							header : "选择金融方案",
							content : dom.prop("outerHTML")
						}
					});
					//自动选择第一个首付比例
					$($(".down-payment .loan-item")[0]).trigger("click");
				}
				else {
					ECar.easyDialog.open({
						container : {
							header : "选择金融方案",
							content : dom.prop("outerHTML")
						}
					});
				}
			});
			//多级联动逻辑
			//选择首付比例
			$(document).on("click", ".down-payment .loan-item", function() {
				if ($(this).hasClass("cur")) {
					return;
				}
				var key = $(this).attr("key");
				$(".stages .loan-item").remove();
				for (var times in data[key]) {
					$(".stages").append("<div class='loan-item' repayPeriod='" + times + "'>" + times + "期</div>")
				}
				$(".down-payment .cur").removeClass("cur");
				$(this).addClass("cur");
				//自动选择第一个分期
				$($(".stages .loan-item")[0]).trigger("click");
			});
			//选择分期
			$(document).on("click", ".stages .loan-item", function() {

				if ($(this).hasClass("cur")) {
					return;
				}
				var key = $(".down-payment .cur").attr("key");
				var times = $(this).attr("repayPeriod");
				$(".loan-organization").remove();

				for (var i = 0; i < data[key][times].length; i++) {
					var tempLoan = data[key][times][i]
					var bankCode = tempLoan.serviceCode;
					switch (bankCode) {
						case "SQCW":
							$(".organization-list").append("\
								<div class='loan-organization' bank='SQCW'>\
									<span class='non-selected'></span>\
									<span class='icon-haocheedai'></span>\
									<div class='payment'>\
										<span class='money'>&yen;" + Math.ceil(tempLoan.monthRepay) +"</span>\
										<span class='unit'>/期</span>\
									</div>\
									<span class='pre-txt'>资质：年龄18-60岁&nbsp;&nbsp;|&nbsp;&nbsp;首付45%以上...</span>\
									<div class='icon-info-box'>\
										<div class='icon-info'></div>\
										<div class='detail-info'>\
											<span class='tit-tag'>资质</span>\
											<span class='txt-tag'>年龄18-60岁&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;首付45%以上，只需身份证&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;无不良信用记录</span>\
											<span class='tit-tag'>卖点</span>\
											<span class='txt-tag'>最高额度50万&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;极速审批2小时&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;灵活调整月供款</span>\
											<i class='top-triangle'></i>\
										</div>\
									</div>\
								</div>");
							break;
						case "SQTYQCJR":
							$(".organization-list").append("\
								<div class='loan-organization' bank='SQTYQCJR'>\
									<span class='non-selected'></span>\
									<span class='icon-gmac'></span>\
									<div class='payment'>\
										<span class='money'>&yen;" + Math.ceil(tempLoan.monthRepay) + "</span>\
										<span class='unit'>/期</span>\
									</div>\
									<span class='pre-txt'>资质：年龄18-60岁&nbsp;&nbsp;|&nbsp;&nbsp;有驾证&nbsp;&nbsp;|&nbsp;&nbsp;无...</span>\
									<div class='icon-info-box'>\
										<div class='icon-info'></div>\
										<div class='detail-info'>\
											<span class='tit-tag'>资质</span>\
											<span class='txt-tag'>年龄18-60岁&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;有驾证&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;无不良信用记录</span>\
											<span class='tit-tag'>卖点</span>\
											<span class='txt-tag'>超低首付仅需20%起&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;最长60期还款期限&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;最快1天放款</span>\
											<i class='top-triangle'></i>\
										</div>\
									</div>\
								</div>");
							break;
						case "PFTH":
							$(".organization-list").append("\
								<div class='loan-organization' bank='PFTH'>\
									<span class='non-selected'></span>\
									<span class='icon-pufa-bank'></span>\
									<div class='payment'>\
										<span class='money'>&yen;" + Math.ceil(tempLoan.monthRepay) + "</span>\
										<span class='unit'>/期</span>\
									</div>\
									<span class='pre-txt'>资质：年龄18-60岁&nbsp;&nbsp;|&nbsp;&nbsp;稳定工作及经...</span>\
									<div class='icon-info-box'>\
										<div class='icon-info'></div>\
										<div class='detail-info'>\
											<span class='tit-tag'>资质</span>\
											<span class='txt-tag'>年龄18-60岁&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;稳定工作及经济收入&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;无不良信用记录</span>\
											<span class='tit-tag'>卖点</span>\
											<span class='txt-tag'>独立专属额度&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;车辆免抵押&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;专员一站式服务</span>\
											<i class='top-triangle'></i>\
										</div>\
									</div>\
								</div>");
							break;
						case "NYYH":
							$(".organization-list").append("\
								<div class='loan-organization' bank='NYYH'>\
									<span class='non-selected'></span>\
									<span class='icon-abchina'></span>\
									<div class='payment'>\
										<span class='money'>&yen;" + Math.ceil(tempLoan.monthRepay) + "</span>\
										<span class='unit'>/期</span>\
									</div>\
									<span class='pre-txt'>资质：年龄18-60岁&nbsp;&nbsp;|&nbsp;&nbsp;稳定工作及经...</span>\
									<div class='icon-info-box'>\
										<div class='icon-info'></div>\
										<div class='detail-info'>\
											<span class='tit-tag'>资质</span>\
											<span class='txt-tag'>年龄18-60岁&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;稳定工作及经济收入&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;无不良信用记录</span>\
											<span class='tit-tag'>卖点</span>\
											<span class='txt-tag'>同行最具竞争力费率&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;最快3天放款&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;多种期数选择</span>\
											<i class='top-triangle'></i>\
										</div>\
									</div>\
								</div>");
							break;
					}
				}
				$(".stages .cur").removeClass("cur");
				$(this).addClass("cur");
				//自动选择第一个银行
				$($(".organization-list .loan-organization")[0]).trigger("click");
			});
			//选择银行
			$(document).on("click", ".organization-list .loan-organization", function() {
				if ($(this).children(".selected").length > 0) {
					return;
				}
				var key = $(".down-payment .cur").attr("key");
				var times = $(".stages .cur").attr("repayPeriod");
				var bank = $(this).attr("bank");
				for (var i = 0; i < data[key][times].length; i++) {
					if (data[key][times][i].serviceCode == bank) {
						myLoan = data[key][times][i];
						break;
					}
				}
				//更新展示金额
				$(".js_loanAmount").html("&yen;" + Math.ceil(myLoan.loanAmount));
				$(".js_firstAmount").html("&yen;" + Math.ceil(myLoan.firstAmount));
				$(".js_monthRepay").html("&yen;" + Math.ceil(myLoan.monthRepay) + "&nbsp;x&nbsp;" + myLoan.repayPeriod + "期");

				$(".loan-organization .selected").removeClass("selected").addClass('non-selected');
				$(this).children(".non-selected").removeClass("non-selected").addClass('selected');
			});
			//点击确定
			$(document).on("click", ".choose-loan .submit", function() {
				dom = $($(".choose-loan").prop("outerHTML"));
				ECar.easyDialog.close();
				firstPopup = false;
				$(".payment-price").html("&yen;" + Math.ceil(myLoan.firstAmount) + "&nbsp;&nbsp;(" + myLoan.firstShare + "%)");
				$(".supply-price").html("&yen;" + Math.ceil(myLoan.monthRepay) + "&nbsp;x&nbsp;" + myLoan.repayPeriod + "期");
				$(".form-way .JS-cur").removeClass('JS-cur');
				$(".stages-btn").show().addClass('JS-cur');
				$(".js-loan").hide();
				//隐藏域赋值
				jsHiddenDataElm.attr("firstShare", myLoan.firstShare);
				jsHiddenDataElm.attr("firstAmount", myLoan.firstAmount);
				jsHiddenDataElm.attr("repayPeriod", myLoan.repayPeriod);
				jsHiddenDataElm.attr("loanAmount", myLoan.loanAmount);
				jsHiddenDataElm.attr("financeServiceName", myLoan.financeServiceName);
				jsHiddenDataElm.attr("monthRepay", myLoan.monthRepay);
				jsHiddenDataElm.attr("interest", myLoan.interest);
				//下定按钮定金变化
				$(".js-bare-fullPay").hide();
				$(".js-bare-loanDeposit").show();
			});
			//选择全款
			$(".js-payall").on("click", function() {
				$(".form-way .JS-cur").removeClass('JS-cur');
				// $(".js-loan").show();
				// $(".stages-btn").hide();
				$(".js-payall").addClass('JS-cur');
				var firstShareTemp = jsHiddenDataElm.attr("firstShare");
				//选中全款则移除贷款数据
				if(firstShareTemp !=undefined){
					jsHiddenDataElm.removeAttr("firstShare");
					jsHiddenDataElm.removeAttr("firstAmount");
					jsHiddenDataElm.removeAttr("repayPeriod");
					jsHiddenDataElm.removeAttr("loanAmount");
					jsHiddenDataElm.removeAttr("financeServiceName");
					jsHiddenDataElm.removeAttr("monthRepay");
					jsHiddenDataElm.removeAttr("interest");
				};
				//下定按钮定金变化
				$(".js-bare-loanDeposit").hide();
				$(".js-bare-fullPay").show();
			});
		}

	};

	detailPayCar.init();

	window.detailPayCar = detailPayCar;
})();